package edu.ccut.saturn.studio.wfg.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnAutoActivityNode;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnName;

public class SaturnAutoActivityNodeLoader extends NodeLoader {

	@Override
	public List<Shape> loadNodes(Element root) {
		NodeList autoNodes = root.getElementsByTagName(SaturnName.XML_NAME);
		List<Shape> autoLists = new ArrayList<Shape>();
		for(int i = 0 ; i<autoNodes.getLength();i++){
			Node auto = autoNodes.item(i);
			if(SaturnName.KEY_NODE_ATTRIBUTE_AUTO.equals(super.getNodeAttributeValue(auto, SaturnName.XML_TYPE))){
				SaturnAutoActivityNode autoNode = new SaturnAutoActivityNode();
				// 基本信息
				autoNode.setDescription(super.getNodeElementValue(auto, Shape.KEY_NODE_DESCRIPTION));
				autoNode.setId(super.getNodeAttributeValue(auto, Shape.KEY_ATTRIBUTE_ID));
				autoNode.setLocation(super.getLocation(auto));
				autoNode.setName(super.getNodeElementValue(auto, Shape.KEY_NODE_NAME));
				autoNode.setNextId(super.getNodeAttributeValue(auto, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID));
				autoNode.setPolymeMode(super.getNodeElementValue(auto, SaturnName.KEY_NODE_ELEMENT_POLYMEMODE));
				autoNode.setSize(super.getSize());
				// 触发信息
				autoNode.setLogicList(super.getSaturnAttributeList(auto, SaturnName.KEY_NODE_ELEMENT_LOGICKEY,SaturnName.KEY_NODE_NAME_KEY, SaturnName.METHOD_GETKEY));
				autoLists.add(autoNode);
			}
		}
		return autoLists;
	}
}
